package com.pheruagor.handmanager.model.business {
    import com.pheruagor.handmanager.model.business.activity.Activity;

    import mx.collections.ArrayCollection;

    /**
     * Member represents all people working for a club
     * It is an abstract class
     */
    public class Member extends Person {

        //-----------------------------------------------------
        // Properties
        //-----------------------------------------------------
        private var m_id:String;
        private var m_clubId:String;
        private var m_avatarPath:String;
        private var m_clubEntryDate:Date;
        private var m_subscription:Number;
        private var m_activities:ArrayCollection;
        private var m_phoneNumber:String;

        //-----------------------------------------------------
        // Initialization
        //-----------------------------------------------------
        public function Member() {
        }

        //-----------------------------------------------------
        // Access
        //-----------------------------------------------------
        /**
         * Member ID
         */
        public function get id():String {
            return m_id;
        }

        /**
         * @private
         */
        public function set id(value:String):void {
            m_id = value;
        }

        /**
         * Member ID
         */
        public function get clubId():String {
            return m_clubId;
        }

        /**
         * @private
         */
        public function set clubId(value:String):void {
            m_clubId = value;
        }

        /**
         * Member avatarPath
         */
        public function get avatarPath():String {
            return m_avatarPath;
        }

        /**
         * @private
         */
        public function set avatarPath(value:String):void {
            m_avatarPath = value;
        }

        /**
         * date of entry in the club
         */
        public function get clubEntryDate():Date {
            return m_clubEntryDate;
        }

        /**
         * @private
         */
        public function set clubEntryDate(value:Date):void {
            m_clubEntryDate = value;
        }

        /**
         * membership fee
         */
        public function get subscription():Number {
            return m_subscription;
        }

        /**
         * @private
         */
        public function set subscription(value:Number):void {
            m_subscription = value;
        }

        /**
         * List of activities made by a member
         */
        public function get activities():ArrayCollection {
            return m_activities;
        }

        /**
         * @private
         */
        public function set activities(value:ArrayCollection):void {
            m_activities = value;
        }

        public function get phoneNumber():String {
            return m_phoneNumber;
        }

        /**
         * @private
         */
        public function set phoneNumber(value:String):void {
            m_phoneNumber = value;
        }

        //-----------------------------------------------------
        // Operation
        //-----------------------------------------------------
        /**
         * Return a deep copy of the Club with the same id
         * TODO : add deep copy on activity
         */
        public function clone():Member {
            var result:Member = new Member();
            result.id = id;
            result.clubId = clubId;
            result.forname = forname;
            result.lastname = lastname;
            result.birthday = birthday;
            result.size = size;
            result.gender = gender;
            result.geneticHand = geneticHand;
            result.avatarPath = avatarPath;
            result.clubEntryDate = clubEntryDate;
            result.subscription = subscription;
            result.phoneNumber = phoneNumber;
            result.activities = new ArrayCollection();
            for each (var activity:Activity in activities) {
                result.activities.addItem(activity.clone());
            }
            return result;
        }

        public static function fromObject(item:Object):Member {
            if (item == null) {
                throw new ArgumentError("item cannot be null");
                return;
            }
            var result:Member = new Member();
            result.id = item.id;
            result.clubId = item.clubId;
            result.forname = item.forname;
            result.lastname = item.lastname;
            result.birthday = item.birthday == "null" ? null : new Date(item.birthday);
            result.size = item.size;
            result.geneticHand = item.geneticHand == "null" ? null : item.geneticHand;
            result.gender = item.gender == "null" ? null : item.gender;
            result.avatarPath = item.avatarPath == "null" ? null : item.avatarPath;
            result.clubEntryDate = item.clubEntryDate == "null" ? null : new Date(item.clubEntryDate);
            result.subscription = item.subscription;
            result.phoneNumber = item.phoneNumber == "null" ? null : item.phoneNumber;
            return result;

        }
        //-----------------------------------------------------
        // Implementation
        //-----------------------------------------------------


    /**
     * Deep comparison with another club
     * TODO : add comparison on activities and position
     */ /* public function equals(member:Member):Boolean {
       var idMatch:Boolean = Utils.numberEquals(member.id, id);
       var avatarPathMatch:Boolean = member.avatarPath == avatarPath;
       var clubEntryMatch:Boolean = Utils.dateEquals(member.clubEntry, clubEntry);
       var subcriptionMatch:Boolean = Utils.numberEquals(member.subscription, subscription);
       var sizeMatch:Boolean = Utils.numberEquals(member.size, size);

       return (idMatch && avatarPathMatch && clubEntryMatch && subcriptionMatch);
     } */
    }
}